import pandas as pd


class person:
    def __init__(self, name, chinese, math, english, science):
        self.name = name
        self.chinese = chinese
        self.math = math
        self.english = english
        self.science = science
        self.total = chinese + math + english + science

    def __repr__(self):
        # 返回的字符串通常包含类名和关键属性，清晰明了
        return f"{self.name}(语文:{self.chinese}数学:{self.math}英语:{self.english}科学:{self.science}总分:{self.total})"


# 读取 Excel 文件
df = pd.read_excel('/Users/zh/学生成绩表.xlsx')

# 所有人的list
all = []
for index, row in df.iterrows():  # iterrows() 逐行迭代
    if index != 0:
        all.append(person(row[0], row[1], row[2], row[3], row[4]))

totalSort = sorted(all, key=lambda s: s.total, reverse=True)
print('前5名是:')
for a in totalSort[:5]:
    print(a)
